« powrót

Budowa serwisu web do zarządzania własnymi projektami (cz. II)

Opublikowano: 2009-11-15 , wyświetlono: 11038

Informacja o stanie repozytorium SVN - ciąg dalszy

Nabrawszy trochę wprawy w posługiwaniu się XML/XSLT zechciałem mieć też w formie html log projektu. Ponownie pracę rozpocząłem od wygenerowania odpowiedniego xml'a.


svn log file:///x:/svnrep/projekt1 --xml > \www\project\svn\projekt1_log.xml
msxsl \www\project\svn\project1_log.xml \www\project\svn\log.xsl > \www\project\svn\project1_log.htm

oraz stworzenia arkusza stylów XSLT użytego do przetwarzania pliku project1_log.xml.


<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" encoding="utf-8"/>

<xsl:template name="replace">
    <xsl:param name="string"/>
    <xsl:choose>
        <xsl:when test="contains($string,'')">
            <xsl:value-of select="substring-before($string,'')"/>
            <br />
            <xsl:call-template name="replace">
                <xsl:with-param name="string" select="substring-after($string,'')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$string"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
    

<xsl:template match="/">
  <html>
    <head>
      <title>SVN Repository - log info</title>
      <link rel="stylesheet" type="text/css" href="svn.css" />      
      <link xmlns="http://www.w3.org/1999/xhtml" rel="stylesheet" type="text/css" href="svn.css" />
    </head>
  <body>

  <h1>SVN Repository - log info</h1>

    
    <a href="index.htm"><xsl:text>&#171;</xsl:text> back to projects list</a>
    <br /><br />
    
    <table border="0" cellspacing="0" cellpadding="5">
      <tr>
        <th width="80">Date</th>
        <th width="50">Revision</th>
        <th width="100">Author</th>
        <th width="400">Comments</th>
      </tr>
    <xsl:for-each select="log/logentry">
      <tr><td>
        <xsl:value-of select="substring(date, 1, 10)"/>
      </td>
      <td>
        <xsl:value-of select="@revision"/>
      </td>
      <td>
        <xsl:value-of select="author"/>
      </td>
      <td>
        <xsl:call-template name="replace">
          <xsl:with-param name="string" select="msg"/>
        </xsl:call-template>
        <!-- <xsl:value-of select="msg"/> -->
      </td></tr>
    </xsl:for-each>
    </table>

  <p class="foot" align="center">
    (c) Chinasoft 2009 http://www.chinasoft.com.pl
  </p>
  
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

To samo możemy zrobić jeżeli chodzi o status projektu. Najpierw eksport danych o projekcie do XMLa, a następnie stworzenie HTMLa za pomocą odpowiedniego arkusza stylów XSLT i wywołanie procesora msxml.exe.


svn status C:\Applications\project1 --xml > \www\project\svn\project_status.xml
msxsl \www\project\svn\project1_status.xml \www\project\svn\status.xsl > \www\project\svn\project1_status.htm


<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" encoding="utf-8"/>

<xsl:template name="replace">
    <xsl:param name="string"/>
    <xsl:choose>
        <xsl:when test="contains($string,'unversioned')">
            <!-- <img src="img/icon_u.png" alt="unversioned" title="unversioned" /> -->
            -
        </xsl:when>
        <xsl:when test="contains($string,'modified')">
            M
        </xsl:when>
        <xsl:when test="contains($string,'add')">
            A
        </xsl:when>
        <xsl:when test="contains($string,'missing')">
            ! 
        </xsl:when>
        <xsl:otherwise>
            ?
            <!-- <img src="img/icon_m" alt="modified" title="modified" /> -->
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:variable name="projectPath" ><xsl:value-of select="status/target/@path"/></xsl:variable>

<xsl:template match="/">
  <html>
    <head>
      <title>SVN Repository - status info</title>
      <link rel="stylesheet" type="text/css" href="svn.css" />      
      <link xmlns="http://www.w3.org/1999/xhtml" rel="stylesheet" type="text/css" href="svn.css" />
    </head>
  <body>

  <h1>Project path: <xsl:value-of select="$projectPath"/></h1>
  
    <a href="index.htm"><xsl:text>&#171;</xsl:text> back to projects list</a>
    <br /><br />
    
    <table border="0" cellspacing="0" cellpadding="5">
      <tr>
        <th width="600">File</th>
        <th width="100">Status</th>
      </tr>
    <xsl:for-each select="status/target/entry">
      <tr><td>
        <xsl:value-of select="substring-after(@path,$projectPath)"/>
      </td>
      <td>
        <xsl:call-template name="replace">
          <xsl:with-param name="string" select="wc-status/@item"/>
        </xsl:call-template>
      </td></tr>
    </xsl:for-each>
    </table>

  <p>
    <ul>
      <li><b>M</b>  modified</li>
      <li><b>A</b>  added</li>
      <li><b>!</b>  deleted</li>
      <li><b>-</b>  unversioned</li>
      <li><b>?</b>  unknown status</li>
    </ul>
  </p>
  <p class="foot" align="center">
    (c) Chinasoft 2009 http://www.chinasoft.com.pl 
  </p>

  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

Do prezentacji użyty jest arkusz css co w poprzedniej części.
W ten prosty sposób uzyskałem dane o stanie repozytorium i projektów w czytelnym formacie. Każdy może oczywiście rozbudować zaprezentowane rozwiązanie o dodatkowe, użyteczne dla siebie informacje.

W następnej części przedstawię w jaki sposób zliczam linie kodu projektu i transformuje je do formatu HTML.


Komentarze: